//
//  HBBadgeViewController.m
//  HBLibary_Example
//
//  Created by Rambo on 2018/11/4.
//  Copyright © 2018年 Rambo. All rights reserved.
//

#import "HBBadgeViewController.h"
#import "HBBadgeView.h"
#import "HBButton.h"
#import "UIImage+HBCategory.h"
#import <HBLibary/HBLibary.h>

@interface HBBadgeViewController ()

@end

@implementation HBBadgeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor greenColor];
    view.frame = CGRectMake(100, 100, 50, 50);
    [self.view addSubview:view];
    
//    HBBadgeView *badgeView = [[HBBadgeView alloc] initWithPresentView:view style:HBBadgeViewStyleRight];
//    badgeView.badgeCount = 10;
//    badgeView.cornerRadius = 3;
//    badgeView.countInsets = UIEdgeInsetsMake(2, 4, 2, 4);
    
    
    [self testButton];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"icon_setting"] forState:UIControlStateNormal];
    [button setTitle:@"测试按钮测试按钮测试" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor redColor];
    [self.view addSubview:button];
    CGSize size = [button sizeThatFits:CGSizeZero];
    button.frame = CGRectMake((self.view.frame.size.width - size.width) *0.5, 200, size.width, size.height);
    
    
    [self testImageView];
    
    __weak typeof(self) weakSelf = self;
    self.hb_panBlock = ^(CGFloat x, UIScreenEdgePanGestureRecognizer *panGesture) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        NSLog(@"%@",strongSelf.title);
//        NSLog(@"%@---%f",self.title ,x);
//        if (x >= 64) {
//            panGesture.enabled = NO;
//            panGesture.enabled = YES;
//        }
    };
}

- (void)dealloc{
    NSLog(@"%s",__func__);
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    self.title = @"test1";
    HBBadgeViewController *vc = [[HBBadgeViewController alloc] init];
    vc.title = @"test2";
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)testButton{
    HBButton *lastButton = nil;
    for (NSInteger index  = 0; index < 4; index++) {
        HBButton *button = [HBButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"icon_setting"] forState:UIControlStateNormal];
        [button setTitle:@"测试按钮" forState:UIControlStateNormal];
        button.backgroundColor = [UIColor redColor];
        [self.view addSubview:button];
        button.translatesAutoresizingMaskIntoConstraints = NO;
        button.imagePoint = index;
        button.extendTouchEdgeInsets = UIEdgeInsetsMake(-10, -10, -10, -10);
//        if (index == 2) {
//            button.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);
//            //        button.imageEdgeInsets = UIEdgeInsetsMake(0, 5, 0, -5);
//            button.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, -5);
//        }
//        button.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
//        button.imageEdgeInsets = UIEdgeInsetsMake(0, 5, 0, -5);
//        button.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, -5);
//        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
//        button.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
        
        NSLayoutConstraint *centerX = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
        [self.view addConstraint:centerX];
        
//        NSLayoutConstraint *centerW = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:200];
//        [self.view addConstraint:centerW];
        
//        NSLayoutConstraint *centerH = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:70];
//        [self.view addConstraint:centerH];
        
        if (lastButton) {
            NSLayoutConstraint *centerY = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:lastButton attribute:NSLayoutAttributeBottom multiplier:1 constant:10];
            [self.view addConstraint:centerY];
        }else{
            NSLayoutConstraint *centerY = [NSLayoutConstraint constraintWithItem:button attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
            [self.view addConstraint:centerY];
        }
        lastButton = button;
    }
    
}


- (void)testImageView{
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = CGRectMake(0, 0, 350, 350);
    UIImage *image = [UIImage imageNamed:@"guide_1"];
    image = [UIImage hb_carveRoundedCornersWithImage:image];
    imageView.image = image;
    [self.view addSubview:imageView];
    imageView.center = self.view.center;
}



@end
